﻿using DataService.Cache.Caching;
using DataService.Cache.IService;
using DataService.Cache.RedisService;
using DataService.Core.ServiceDTO;
using DataService.DataAccessLayer;
using DataService.IService;
using System;
using System.Collections.Generic;
using System.Text;

namespace DataService.Main
{
    public static class CacheDAL
    {
        /// <summary>
        /// redis 读/写 ;主机
        /// </summary>
        public readonly static ICache Redising = null;

        /// <summary>
        /// redis 读；从机
        /// </summary>
        public readonly static ICache RedisReading = null;

        /// <summary>
        /// MemoryCache缓存；单进程 10万容量
        /// </summary>
       public readonly static ICache MemoryCacheing = null;
        /// <summary>
        /// 字典缓存；单进程 10万容量
        /// </summary>
        public readonly static ICache DictionaryCacheing = null;

        //【6379为主库,7001是备份库同时是6379的从库】【6380和6390是7001的从库】【6379只写，6380、6390为只读库】
        //【8390为从机，6379挂掉时,8390为7001的主库】
        /// <summary>
        /// 多地址时，第一个必须是主库，第二个第三个为从库；第一个地址是不可访问时，它会自动切换到第二地址
        /// 单地址： server=127.0.0.1:6379;password=pass;db=7
        /// 主备地址：server=127.0.0.1:6379,127.0.0.1:7000;password=test;db=9;
        /// 多主备库: server=127.0.0.1:6000,127.0.0.1:7000,127.0.0.1:6379;password=test;db=3;timeout=7000
        /// </summary>
        private readonly static string _RedisConfig = "server=127.0.0.1:6379,127.0.0.1:8390;password=695845;db=0";
        /// <summary>
        /// 读；配置；第一个地址是不可访问时，它会自动切换到第二地址
        /// </summary>
        private readonly static string _ReadConfig = "server=127.0.0.1:6390,127.0.0.1:6380;password=695845;db=0";
        static CacheDAL()
        {
            FullRedis fullRedis = new FullRedis();
            fullRedis.Init(_RedisConfig);
            Redising = fullRedis;


            FullRedis readFullRedis = new FullRedis();
            readFullRedis.Init(_ReadConfig);
            RedisReading = readFullRedis;

            MemoryCacheing = DataMemoryCache.Instance;
            DictionaryCacheing = DictionaryCache.Instance;

        }
        /// <summary>
        /// 字典缓存实例；业务实例，用完记得释放
        /// </summary>
        /// <returns></returns>
        public static DictionaryCache DictionaryCacheInstance()
        {
            return new DictionaryCache();
        }
        ///// <summary>初始化配置;调用实例Redis；一定要释放</summary>
        //public static FullRedis RedisInstance(string config)
        //{
        //    FullRedis fullRedis = new FullRedis();
        //    fullRedis.Init(config);
        //    return fullRedis;
        //}
    }
}
